<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title></title>
<link href="houtai/css/style.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="houtai/js/main.js"></script>
<script type="text/javascript">
function breakpage(){
	
		var pa=document.getElementById("inpage").value;
		if(isNaN(pa)||pa.indexOf(' ')>=0||pa==""){
	  		alert("请输入数字！");
	    }else if(pa<0 || pa>${page.lastPage}){
	         alert("该页面不在范围！请重新输入！");
	    }else if(pa.length==0){
	    alert("请输入数字！");
	    }else{
	   		
	   	window.location.href="<%=request.getContextPath()%>/CourseServlet?param=allCourses&page="
					+ pa + "&time=" + new Date().getTime();
		}
	}
	function sel(ck) {

		var was = document.getElementsByName("checkbox2");
		for (var int = 0; int < was.length; int++) {
			was[int].checked = ck.checked;
		}

	}

	function sele(ck) {
		var ws = document.getElementById("checkbox1");
		if (ck.checked == false) {
			ws.checked = "";
		}
		var was = document.getElementsByName("checkbox2");

		for (var int = 0; int < was.length; int++) {
			if (was[int].checked == false) {
				return;
			}
		}
		ws.checked = true;

	}
	var xmlhttp;
	function ajaxeditstate(couid) {
		var c = document.getElementById("coustate" + couid).innerHTML;
		var coustate;
		var cc;
		if (c == "可报名") {
			coustate = 2;
			cc = "<报名结束>";
		}
		if (c == "可购买") {
			coustate = 4;
			cc = "<已下架>";
		}
		if (confirm("是否改为" + cc + "?")) {
			if (c == "可报名") {
				document.getElementById("coustate" + couid).innerHTML = "报名结束";
				document.getElementById("btstate" + couid).style.display = "none";
			}
			if (c == "可购买") {
				document.getElementById("coustate" + couid).innerHTML = "已下架";
				document.getElementById("btstate" + couid).style.display = "none";
			}
			xmlhttp = new XMLHttpRequest();
			xmlhttp.open("get", "CourseServlet?param=stateUpdate&couid="
					+ couid + "&coustate=" + coustate + "&time="
					+ new Date().getTime(), true);
			xmlhttp.send(null);
		}
	}

	var xmlhttp;
	function ajaxeditstate(couid) {
		var c = document.getElementById("coustate" + couid).innerHTML;
		var coustate;
		var cc;
		if (c == "可报名") {
			coustate = 2;
			cc = "<报名结束>";
		}
		if (c == "可购买") {
			coustate = 4;
			cc = "<已下架>";
		}
		if (confirm("是否改为" + cc + "?")) {
			if (c == "可报名") {
				document.getElementById("coustate" + couid).innerHTML = "报名结束";
				document.getElementById("btstate" + couid).style.display = "none";
			}
			if (c == "可购买") {
				document.getElementById("coustate" + couid).innerHTML = "已下架";
				document.getElementById("btstate" + couid).style.display = "none";
			}
			xmlhttp = new XMLHttpRequest();
			xmlhttp.open("get", "CourseServlet?param=stateUpdate&couid="
					+ couid + "&coustate=" + coustate + "&time="
					+ new Date().getTime(), true);
			xmlhttp.send(null);
		}
	}
	function select() {
		var text = document.getElementById("textfield");
		var name=document.getElementById("name");
			if (text != "") {
			if (confirm("是否要查询该信息")) {
				name.submit();
			} 
				
				return false;
			
		}
	}
</script>
</head>
<body>
	<table width="100%" height="100%" border="0" cellspacing="0"
		cellpadding="3">
		<tr>
			<td style="height:25px; background-color:#f3f3f3; font-weight:bold"
				valign="top">&nbsp;&nbsp;&nbsp;&nbsp;当前位置： <img
				src="houtai/images/arrow.gif" align="absmiddle">&nbsp;&nbsp;soda创业教育平台&nbsp;&nbsp;
				<img src="houtai/images/arrow.gif" align="absmiddle">&nbsp;&nbsp;后台管理&nbsp;&nbsp;
				<img src="houtai/images/arrow.gif" align="absmiddle">&nbsp;&nbsp;课程管理
			</td>
		</tr>
		<tr>
			<td
				style="height:34px; background-image:url(houtai/images/main_header.gif); border-bottom:1px solid #cfd8e0; padding:0px">
				<table width="100%" border="0" cellspacing="0" cellpadding="0">
					<tr>
						<td width="20" height="34"><img
							src="houtai/images/main_headerL.gif" width="20" height="34"></td>
						<td style="color:#90c8e8;"><img
							src="houtai/images/icon_card.gif" width="16" height="16"
							align="absmiddle">&nbsp;&nbsp;<strong>课程管理</strong></td>
						<td align="right" class="white" style="padding-right:20px"><a
							href="houtai/pages/class/add.jsp" class="barBtn"
							onClick="location.href='add.jsp'"><img
								src="houtai/images/5.png" align="absmiddle"> 新增</a> <a
							href="javascript:history.go(-1)" class="barBtn"><img
								src="houtai/images/btn_left.gif" align="absmiddle"> 后退</a> <a
							href="javascript:history.go(+1);" class="barBtn"><img
								src="houtai/images/btn_right.gif" align="absmiddle"> 前进</a> <a
							href="CourseServlet?param=allCourses" class="barBtn"><img
								src="houtai/images/btn_refresh.gif" align="absmiddle"> 刷新</a></td>
					</tr>
				</table>
			</td>
		</tr>
		<tr>
			<td
				style="height:30px; background-color:#bddbff; border-bottom:1px solid #cfd8e0;">
				<form action="CourseServlet?param=allCourses" method="post" id=name>
				<table width="100%" border="0" cellpadding="3" cellspacing="1"
					class="table1">
					
					<TR>
						<th width="10%" align="center">课程名称</th>
						<td width="20%" class="BGCgray"><input type="text"
							name="textfield" id="textfield" value="${couCondition.couName }"></td>
						<th width="10%" align="center"><BUTTON style="HEIGHT:25px"
								onClick="return select()">
								<img src="houtai/images/btn_search.gif" width="16" height="16"
									align="absmiddle"> 查询
							</BUTTON></th>
					</TR>

				</table>
				</form>
			</td>
		</tr>
		<tr>
			<td height="100%" valign="top">
				<div style="overflow:auto;height:100%; width:100%">
					<table width="100%" border="0" cellpadding="3" cellspacing="1"
						class="table1">
						<TR>
							<th align="center"><input type="checkbox" name="checkbox1"
								id="checkbox1" onclick="sel(this)" /></th>
							<th align="center">课程名</th>
							<th align="center">地点</th>
							<th align="center">课程类型</th>
							<th align="center">课程状态</th>
							<th align="center">讲师</th>
							<th align="center">金额</th>
							<th width="200" align="center">操作</th>
						</TR>
						<c:forEach items="${requestScope.cou }" var="co">


							<TR>
								<td align="center"><input type="checkbox" name="checkbox2"
									onclick="sele(this)" /></td>
								<td align="center">${co.couName }</td>
								<td align="center">${co.couAddress }</td>
								<td align="center">${co.couType==1?"现场课程":co.couType==0?"在线课程":"未知错误"}</td>
								<td align="center" id="coustate${co.couId}">${co.couState==1?"可报名":co.couState==2?"报名结束":co.couState==3?"可购买":co.couState==4?"已下架":"未知错误" }</td>
								<td align="center">${co.user.useName }</td>
								<td align="center">${co.couMoney }</td>

								<TD width="200" align="center">
									<BUTTON style="height:21px; font-size:12px"
										onClick="javascript:if (confirm('查看该信息？')) location.href='<%=request.getContextPath()%>/CourseServlet?id=${co.couId }&param=showCourseById&s=show';else return;">查看</BUTTON>
									<BUTTON style="height:21px; font-size:12px"
										onClick="javascript:if (confirm('编辑该信息？')) location.href='<%=request.getContextPath()%>/CourseServlet?id=${co.couId }&param=showCourseById&s=edit';else return;">编辑</BUTTON>

									<c:if test="${co.couState==3&&co.couType==0}">
										<BUTTON id="btstate${co.couId }"
											style="height:21px; font-size:12px"
											onClick="ajaxeditstate(${co.couId})">下架</BUTTON>
									</c:if> <c:if test="${co.couState==1&&co.couType==1}">
										<BUTTON id="btstate${co.couId }"
											style="height:21px; font-size:12px"
											onClick="ajaxeditstate(${co.couId})">结课</BUTTON>
									</c:if>
								</TD>
							</TR>
						</c:forEach>
					</table>
					<table width="100%" border="0" cellspacing="0" cellpadding="0">

						<tr>
							<td width="20%" height="25"><table border="0"
									cellspacing="0" cellpadding="3">
									<tr>
										<td><a
											href="<%=request.getContextPath()%>/CourseServlet?param=allCourses&page=1"
											style="color:black;">首页</a></td>
										<td><a
											href="<%=request.getContextPath() %>/CourseServlet?param=allCourses&page=${page.page-1 }"
											style="color:black;">上一页</a></td>
										<td><a
											href="<%=request.getContextPath() %>/CourseServlet?param=allCourses&page=${page.page+1 }"
											style="color:black;">下一页</a></td>
										<td><a
											href="<%=request.getContextPath() %>/CourseServlet?param=allCourses&page=${page.lastPage }"
											style="color:black;">尾页</a></td>
									</tr>
								</table></td>
							<td width="20%" align="center">
								<table border="0" cellspacing="0" cellpadding="3">
									<tr>
										<td><a href="javascript:breakpage();"
											style="color:black;">GO</a></td>

										<td><input id="inpage" name="inpage" type="text" size="3"
											style="width:25;height:18"> /页</td>

									</tr>
								</table>
							</td>

							<td width="20%" align="right">共${page.total}条记录显示到${page.page }/${page.lastPage }</td>
						</tr>
					</table>
				</div>
			</td>
		</tr>
	</table>
</body>
</html>